﻿using SuperSocket;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xc.DataAccess.Protocoals.WaterMeters.Models;
using Xc.DataAccess.Protocoals.WaterMeters.Services;

namespace Xc.WaterMeters.ServerHosts.Models
{
    public class AppSettings
    {
        public AppSettings()
        {

        }
        /// <summary>
        /// 服务器监听信息
        /// </summary>
        public Options Options { get; set; } = new Options() { Ip = "Any", Port = 4040 };
        /// <summary>
        /// 通知路径
        /// </summary>
        public SortedSet<string> NotifyPath { get; set; } = new SortedSet<string>();
        /// <summary>
        /// 重新生成通知路径
        /// </summary>
        public void Regenerate()
        {
            Notifys.Clear();
            var types = typeof(IMeterHandleService).Assembly.GetTypes().Where(p => p.IsAssignableTo(typeof(MeterFrameRxDataSegmentBase)) && p.IsAbstract == false && p.IsPublic).ToArray();
            foreach (var item in types)
            {
                Notifys.TryAdd(item.Name, NotifyPath.Select(p => p + item.Name).ToArray());
            }
        }
        /// <summary>
        /// 可以通知的列表
        /// </summary>
        public Dictionary<string, string[]> Notifys { get; set; } = new Dictionary<string, string[]>();
    }


}
